<?php
// $Id$

/**
 * Controller_Admin_Cbquick 控制器
 */
class Controller_Admin_Cbquick extends Controller_Abstract
{
	function _format_appendSql()
	{
		if (isset($_SESSION['acct']))
		{
			if ($_SESSION['acct']['admin_id'] == -1 && $_SESSION['acct']['agent_id'] == -1)
			{
				//为管理
				//$append['']
				$append = null;
	
			}else
			{
				//$append['admin_id'] = $_SESSION['acct']['admin_id'];
				$append['agent_id'] = Acct::_get_have_acctid($_SESSION['acct']['id'], $_SESSION['acct']['admin_id']);
				$append['agent_id'][] = $_SESSION['acct']['id'];
			}
		}
		return $append;
	}
	function actionIndex()
	{
		
			
		
     	$data = Cbnumlist::find('agent_id = 0')->order('sipcode asc')->getAll();
     	$this->_view['data'] = $data;
	}
	
	function actionset()
	{
		$sipcode = trim($this->_context->sipcode);
		$num = trim($this->_context->num);
		$acctname = trim($this->_context->acctname);
		$desc = trim($this->_context->desc);
		$agent_id = Acctuser::find('acctname = ?',$acctname)->getOne();
		if ($agent_id->id())
		{
			if($_SESSION['acct']['acclevel'] != 3)
			{
				$appsql = $this->_format_appendSql();
				
				if (!is_null($appsql))
				{
					if (!in_array($agent_id->agent_id, $appsql['agent_id']))
					{
						exit('亲亲号修改失败');
					}
				}
			}
			if($num == '')
			{
				try {
					$cbnum = Cbnumlist::find('sipnum = ? ',$sipcode)->getOne();
				$cb = Cbbind::find('acctname = ? and sipnum = ?',$acctname,$cbnum->sipcode)->getOne();
				Cbbind::meta()->deleteWhere('acctname = ? and sipnum = ?',$acctname,$cbnum->sipcode);
				}catch (Exception $e){
				}
				
				exit('清空亲亲号成功');
			}
			
			Syslog::logs("修改快号：{$sipcode}={$num}");
			QDB::getConn('fscall')->execute("call fscall.webacct_cbbindnum('{$acctname}','{$num}','{$sipcode}','{$desc}')");
			
			exit('亲亲号修改成功!');
				
		}
		//exit("call fscall.acct_cbbindnum('{$acctname}','{$num}','{$sipcode}')");die;
	}
}


